package com.wwwarehouse.resource_center.fragment.productiontools;


import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.fragment.CommonBasePagerFragment;
import com.wwwarehouse.common.tools.ToastUtils;
import com.wwwarehouse.resource_center.bean.goods.CategoryBean;
import com.wwwarehouse.resource_center.bean.maintenanceunit.UpdateUnitBean;
import com.wwwarehouse.resource_center.constant.ResourceConstant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Creator by zhenwang.xiang on 2017/11/23 14:56
 * Description: 选择分类外面的viewpager页面
 */
 

public class ChooseCategroyViewPagerFragment extends CommonBasePagerFragment {

    private ArrayList<CategoryBean> mData;
    @Override
    public void requestDatas() {
        super.requestDatas();
        mData=new ArrayList<>();

        requestHttp();
    }

    private void requestHttp() {
        Map<String, Object> map = new HashMap<>();
        map.put("page", "1");
        map.put("size", "7");
        loadData(ResourceConstant.INSERT_UNIT, map, 0);
    }

    @Override
    public void onRefreshListener() {
        requestHttp();
    }

    @Override
    public void onLoadSuccess(String data, int what) {
        if (0 == what) {
            UpdateUnitBean bean = JSON.parseObject(data, UpdateUnitBean.class);
            if (null != bean) {
                Bundle bundle = new Bundle();
                try {
                    setData(mData.size(), 7, new ChooseCategroyFragment().getClass().getName(), bundle, mData);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void onLoadError(String errorInfo) {
        ToastUtils.showToast(errorInfo);
    }
}
